package com.example.interpreter2;
import java.util.StringTokenizer;

/**
 * "LOOP 2 PRINT 你好 BREAK END PRINT 你好 SPACE 世界 世界 BREAK" 文法规则定义如下：
 * expression ::= command*
 * command ::= loop | primitive
 * loop ::= LOOP [number] expression END
 * primitive ::= PRINT [str] | BREAK | SPACE
 */
public class Context {

    private StringTokenizer tokenizer;
    private String currentToken;

    public Context(String input) {
        this.tokenizer = new StringTokenizer(input);
        nextToken();
    }

    public String getCurrentToken() {
        return currentToken;
    }

    public String nextToken() {
        if (this.tokenizer.hasMoreTokens()) {
            this.currentToken = this.tokenizer.nextToken();
        } else  {
            this.currentToken = null;  
        }
        return currentToken;
    }

    public void skipToken(String token) {
        nextToken();
    }

    public int currentNumber() {
        return Integer.parseInt(currentToken);
    }
}
